#!/bin/bash
uri=~/Pictures/$1
j=0
for i in `ls -1 $uri`
do
	files[j]=$i
	j=$(( $j + 1 ))
done

curr=`gsettings get org.gnome.desktop.background picture-uri | awk -F"/" '{print substr($NF,0,length($NF))}'`
index=0
for file in ${files[@]}
do
	index=$(( $index + 1 ))
	if [ "$file" = "$curr" ];then
		break
	fi
done
if [ $index -eq ${#files[@]} ];then
	index=0
fi
gsettings set org.gnome.desktop.background picture-uri "${uri}/${files[$index]}"
